﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common.DEncrypt;

namespace Maticsoft.Web.wap
{
    public partial class FindPwd : BasePage
    {
        protected void Page_Load( object sender, EventArgs e )
        {
            AjaxProcess();
        }

        protected void AjaxProcess( )
        {
            if (!string.IsNullOrEmpty(Request.QueryString["sync"]) && Request.QueryString["sync"] == "true")
            {
                BLL.SendMsg msgBLL = new BLL.SendMsg();
                List<Model.SendMsg> list = msgBLL.GetListByMobile(Request.QueryString["username"]);
                if (list.Count > 0)
                {
                    Model.SendMsg msgModel = list[0];
                    if (msgModel.VerifyCode != Request.QueryString["code"])
                    {
                        Response.Write("-1");
                        Response.End();
                    }

                    if (((DateTime)msgModel.CreateTime).AddMinutes(10) < DateTime.Now)
                    {
                        Response.Write("-2");
                        Response.End();
                    }

                    msgModel.Status = 2;
                    msgBLL.Update(msgModel);

                    BLL.Members meBLL = new BLL.Members();
                    Model.Members meModel = new Model.Members();
                    meModel = meBLL.GetModel(Request.QueryString["username"]);
                    if (meModel == null)
                    {
                        Response.Write("-3");
                        Response.End();
                    }

                    meModel.Password = DEncrypt.Encrypt(Request.QueryString["pwd"]);
                    meModel.UpdateTime = DateTime.Now;
                    meBLL.Add(meModel);

                    Response.Write("1");
                    Response.End();
                }
            }
        }
    }
}